// components/navTop/navTop.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    isTabBar: true, // 是否隐藏顶部tabbar
    switchIcon: "http://59.110.237.148/tsy/static_file/applets_21cake/images/top-icon.png", // 顶部更多图标
    // 顶部tabbar数据
    navData: [{
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/home-off.png",
        title: "首页"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/classify-off.png",
        title: "分类"
      },
      {
        src: "http://59.110.237.148/tsy/static_file/applets_21cake/images/my-off.png",
        title: "个人"
      }
    ], // 导航数据
    shareInfo: {
      title: '全新品种蛋糕，等你来尝！', //自定义转发标题
      path: '/pages/home/home', //分享页面路径
      imageUrl: 'http://59.110.237.148/tsy/static_file/applets_21cake/images/banner1.jpg' //分享图片 宽高比 5:4
    }
  },

  /**
   * 组件的方法列表
   */
  methods: {

    // 跳转消息页面
    onGoInfo: function() {
      wx.showToast({
        title: '暂未开放',
        icon: "none"
      })
    },
    // 跳转购物车
    onGoTOCart: function() {
      this.CloseNav();
      wx.navigateTo({
        url: '/pages/cart/cart'
      });
    },
    // 跳转首页
    gotoHome: function() {
      this.CloseNav();
      wx.switchTab({
        url: '/pages/home/home'
      });
    },
    // 关闭顶部展开分类栏
    CloseNav: function() {
      if (!this.data.isTabBar) {
        this.setData({
          isTabBar: false
        });
        this.setData({
          switchIcon: "http://59.110.237.148/tsy/static_file/applets_21cake/images/top-icon.png"
        });
      }

    },
    // 点击切换tabbar页面
    switchTab: function(e) {
      switch (e.currentTarget.dataset.index) {
        case 0:
          this.switchNav();
          wx.switchTab({
            url: '/pages/home/home'
          });
          break;
        case 1:
          this.switchNav();
          wx.switchTab({
            url: '/pages/classify/classify'
          });
          break;
        case 2:
          this.switchNav();
          wx.switchTab({
            url: '/pages/my/my'
          });
          break;
        default:
          this.switchNav();
          wx.switchTab({
            url: '/pages/home/home'
          });
          break;
      }
    },
    // 点击显隐顶部tabbar导航栏
    switchNav: function(e) {
      if (this.data.isTabBar) {
        var pages = getCurrentPages() //获取加载的页面
        var currentPage = pages[pages.length - 1] //获取当前页面的对象
        var url = currentPage.route //当前页面url
        var options = currentPage.options //如果要获取url中所带的参数可以查看options

        this.setData({
          switchIcon: "http://59.110.237.148/tsy/static_file/applets_21cake/images/menu-hide.png"
        })
      } else {
        this.setData({
          switchIcon: "http://59.110.237.148/tsy/static_file/applets_21cake/images/top-icon.png"
        })
      }
      this.setData({
        isTabBar: !this.data.isTabBar
      });

    }
  }
})